package session;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Create By IntelliJ IDEA
 *
 * @Author: jsonor
 * @Create-Time: 2017/10/10 10:33
 * @Description: Session
 */
@WebServlet(name = "s1", urlPatterns = "/s1")
public class Session1Servlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {

    /**
     * 获取JSESSIONID对应在服务器上存储的Session -> HashMap()
     */
    HttpSession session = request.getSession();

    /**
     * 从服务器端的JSESSIONID中对应的数据取出来
     */
    Object username = session.getAttribute("username");

    response.getWriter().println("username value from session " + username);
  }
}
